//文件压缩工具类
const compressing = require('compressing');
const compress = {
    //验证必填项
    async zip(dirname, savedir, filename) {
        dirname = fttDirPath(dirname);
        savedir = `${fttDirPath(savedir)}/${filename}.zip`;
        await compressing.zip.compressDir(dirname, savedir);
        return savedir;
    }
}

module.exports = compress;

function fttDirPath(dirname, sign) {
    let slet = dirname.length;
    let lastStr = dirname.substring(slet - 1, slet);
    if (sign) {
        if (lastStr != "/") {
            dirname = dirname + "/";
        }
    } else {
        if (lastStr == "/") {
            dirname = dirname.substring(0, slet - 1);
        }
    }
    return dirname;
}